package com.lyn.common.base;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GlobalExceptionInterceptor implements Interceptor {
    //Logger log = LoggerFactory.getLogger(in.getController().getClass());
    Logger log = LoggerFactory.getLogger(GlobalExceptionInterceptor.class);
    @Override
    public void intercept(Invocation in) {
        try {
            in.invoke();
        } catch (Exception e) {
            //log.error中字符串参数是异常信息描述，最后一个参数Exception是异常堆栈信息。
            //必须打印堆栈信息到日志文件才便于定位错误。
            log.error("controller层全局异常拦截：{}", e.getMessage(), e);
            in.getController().renderError(500, "error.html");
        }
    }

}
